﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CommonTools;
using MotionIoLib;
using Communicate;
using System.Windows.Forms;
using System.Diagnostics;
using System.Threading;
using UserCtrl;
using BaseDll;
using UserData;
using HalconDotNet;
using System.IO;
using OtherDevice;
using System.Threading.Tasks;
using PlugIn;
using Sunny.UI;
using VisionBaseLib;
using HY_UPHMgr;
using DBMgrLib;

using System.Drawing;

namespace StationDemo
{
    public class UserConfig
    {

        public static string str_SN = "";
        public static bool b_isScan = false;
        public static void CloseHardWork()
        {
            ResetIO();
            AlarmMgr.GetIntance().StopAlarmBeet();
            TcpMgr.GetInstance().CloseAllEth();
            MotionMgr.GetInstace().Close();
            IOMgr.GetInstace().Close();
        }
        public static void ResetIO()
        {
            IO_OUT.蜂鸣.Set(false);      
            IO_OUT.双色灯绿.Set(false);
            IO_OUT.双色灯红.Set(false);
        }
        public static void AddStation()
        {

           
            Station_三角测量 station_Load = new Station_三角测量(StationMgr.GetInstance().GetStation(Station.三角测量站.ToString()), new Param_Load(), new Point_Load(), new Config_Load());         
            StationMgr.GetInstance().AddStation(new StationForm(station_Load, station_Load.station_Param, station_Load.station_Point, station_Load.station_Config, null), Station.三角测量站.ToString(), station_Load);


           

        }
        public static bool Funtion_运行前处理()
        {
            //List<string> list_Err = HY_AllConsumables.ConsumeFactory.Ins._Consume.GetWarningList();
            //if (list_Err != null && list_Err.Count > 0)
            //{
            //    string msg = "";
            //    foreach (var item in list_Err)
            //    {
            //        msg += $"{item},";
            //    }
            //    if (AlarmMgr.GetIntance().WarnWithDlg((int)AlarmList.耗材使用完毕, new string[] { "继续运行", "退出运行" }, new string[] { $"耗材使用完毕:{msg}" }) == WaranResult.Custom2)
            //        return false;
            //}
            StationStateHelper.OnTest_ShowStep("系统", "正在自动运行", LogType.Info);
            return true;
        }
        public static void Funtion_暂停时处理()
        {
            StationStateHelper.OnTest_ShowStep("系统", "正在暂停中", LogType.Warn);
        }
        public static void Funtion_恢复时处理()
        {
            StationStateHelper.OnTest_ShowStep("系统", "正在自动运行", LogType.Info);
        }
        public static void Funtion_停止时处理()
        {
            UserConfig.ResetIO();
            UPHTimeMgr.Instance.StopAll();
            LoadSeverMgr.Instance.Stop();
            GlobalVariable.g_StationState = StationState.StationStateEmg;
            StationStateHelper.OnTest_ShowStep("系统", "点击停止", LogType.Err);
        }
        public static bool Function_全机回零()
        {
            try
            {
                Station_三角测量 station_Load = (Station_三角测量)StationMgr.GetInstance().GetStation(Station.三角测量站.ToString());
                station_Load.Function_气缸复位();
              
                // Form1.OnTest_ShowHome("左右图卡气缸复位完成", 10);
                bool bResult = true;


                try
                {
                    bResult &= station_Load.Function_工站回零();
                }
                catch (Exception)
                {
                    bResult &= false;
                }

                if (!bResult)
                {
                    return false;
                }
                Form1.OnTest_ShowHome("回零完成", 100);
                return true;
            }
            catch (Exception ex)
            {
                UIMessageBox.Show(ex.Message);
                return false;
            }
        }
        public static void InitOtherParamter()
        {
            //VisionBaseMgr.GetInstance().Init(VisionType.HY视觉);
            //VisionBaseMgr.GetInstance().Function_Hide();
            //Thread.Sleep(500);
            //VisionBaseMgr.GetInstance().Function_切换机种("aoni");
            ////VisionDataMgr.GetInstance().Read();
            //Vision_组装定位Mgr.GetInstance().Read();
            //TrayDataMgr.GetInstance().Read();
            if(true)
            {   
                //启用数据库
                DeviceDataCollect.GetInstance().Function_SaveInDataBase(true);
                DeviceDataCollect.GetInstance().DeleteHistoryFile(30);//30天
                SQLiteMgr.GetInstance().Init();
            }
            else
            {
                //不启用数据库
                DeviceDataCollect.GetInstance().Function_SaveInDataBase(false);
                DeviceDataCollect.GetInstance().DeleteHistoryFile(30);//30天

            }
            UPHTimeMgr.Instance.InitData();
            UPHTimeMgr.Instance.SetDirPath(@"D:\HY System","AONI02");
            //下段用于更换保存内容后删除原本的数据库
            //  DBCustomTable.Function_DropDataBase();
            //DBCustomTable.Function_DropTable("TestResult锁付");
        }

    }
}
